package panel.viewSpots.navigation
{
	import assists.HtmlText;
	import assists.SizeManager;
	import assists.TextFieldUtils;
	import assists.TimeToStr;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import panel.stars.StarGroup;
	
	public class PaoPaoComp extends Sprite
	{
		private var _loader:ResourceLoader;
		private var _nameTxt:TextField;
		private var _timeTxt:TextField;
		private var _starGroup:StarGroup;
		private var _musicBtn:BtnClouree;
		private var _detailBtn:BtnClouree;
		private var _backGround:Sprite;
		private var _scaleOff:Number;
		private var _rowDis:Number;
		private var _onMusic:Function;
		private var _onDetail:Function;
		private var _data:Object;
		public function PaoPaoComp(loader:ResourceLoader)
		{
			_loader = loader;
			super();
			init();
		}
		
		private function init():void
		{
			_backGround =new Sprite();
			var bit:Bitmap = _loader.getImage("paopao");
			bit.scaleX = bit.scaleY = SizeManager.changeToAutosize(0.75,bit.width);
			bit.scaleX = bit.scaleX + 0.1;
			bit.x = -bit.width/2;
			bit.y = -bit.height/2;
			_backGround.addChild(bit);
			this.addChild(_backGround);
			_rowDis = bit.height * 0.05;
			
			_nameTxt = new TextField();
			_nameTxt.mouseEnabled = false;
			_nameTxt.autoSize = "left";
			this.addChild(_nameTxt);
			_timeTxt = new TextField();
			_timeTxt.mouseEnabled = false;
			_timeTxt.autoSize = "left";
			this.addChild(_timeTxt);
			
			_starGroup = new StarGroup();
			this.addChild(_starGroup);
			
			_musicBtn = new BtnClouree();
			_musicBtn.label("播放音乐");
			_musicBtn.addEventListener(MouseEvent.CLICK,musicHandler);
			_musicBtn.width = _backGround.width * 0.4;
			_musicBtn.height = _backGround.height * 0.25;
			this.addChild(_musicBtn);
			
			_detailBtn = new BtnClouree();
			_detailBtn.label("查看详细");
			_detailBtn.addEventListener(MouseEvent.CLICK,detailhadnler);
			_detailBtn.width = _backGround.width * 0.4;
			_detailBtn.height = _backGround.height * 0.25;
			this.addChild(_detailBtn);
			
		}
		
		protected function detailhadnler(event:MouseEvent):void
		{
			_onDetail(_data);
		}
		
		protected function musicHandler(event:MouseEvent):void
		{
			_onMusic(_data.music,_data.name);
			this.visible = false;
		}
		
		public function set onMusic(value:Function):void
		{
			_onMusic = value;
		}
		
		public function set onDetail(value:Function):void
		{
			_onDetail = value;
		}
		
		public function show(data:Object):void
		{
			_data = data;
			TextFieldUtils.setHtmlText(_nameTxt,HtmlText.formatSizeColor(data.name,0));
			
			TextFieldUtils.setHtmlText(_timeTxt,HtmlText.formatSizeColor("游览时间：" + TimeToStr.timeChangeToStr(data.time * 1000),0));
			
			_starGroup.starLevel = data.star;
			resize();
		}
		
		public function changeScale(xScale:Number,yScale:Number):void
		{
			_backGround.scaleY = yScale;
			if(yScale == -1)
			{
				_scaleOff = _backGround.height * 0.25;
			}else
			{
				_scaleOff = 5;
			}
			resize();
		}
		
		private function resize():void
		{
			
			_nameTxt.x = -　_backGround.width / 2 +　(_backGround.width / 2 - _nameTxt.width) / 2;
			_nameTxt.y = _scaleOff - _backGround.height / 2;
			_timeTxt.x = -_backGround.width / 2 +　(_backGround.width / 2 - _timeTxt.width) / 2 + _backGround.width / 2;
			_timeTxt.y = _scaleOff - _backGround.height / 2;
			_starGroup.y = _rowDis + _nameTxt.y + _nameTxt.height;
			_starGroup.x = -_backGround.width / 2 +　(_backGround.width - _starGroup.width) / 2;
			_musicBtn.y = _rowDis + _starGroup.y +　_starGroup.height;
			_musicBtn.x = -_backGround.width / 2 +　(_backGround.width / 2 - _musicBtn.width) / 2;
			_detailBtn.y = _rowDis + _starGroup.y +　_starGroup.height;
			_detailBtn.x = -_backGround.width / 2 +　(_backGround.width / 2 - _detailBtn.width) / 2 + _backGround.width / 2;
			
		}
	}
}